<?php
if($_POST) {
    require '../../lib/init.php';

    $name = htmlspecialchars(trim($_POST['name']));
    $mail = htmlspecialchars(trim($_POST['mail']));
    $question = htmlspecialchars(trim($_POST['question']));
    $title = htmlspecialchars(trim($_POST['title']));
    $nfo = 'IP: '.$_SERVER['REMOTE_ADDR'].' Host: '.gethostbyaddr($_SERVER['REMOTE_ADDR']);

    $message;
    $message .= '<h2>'.$title.'</h2>';
    $message .= 'Подател: '.$name.chr(13);
    $message .= 'E-mail: '.$mail.chr(13);
    $message .= 'Питане: '.$question.chr(13);
    $message .= '<br /><hr /><br />Инфо за подателя: '.$nfo;

    $headers  = 'From: '.$name.'<'.$mail.">\r\n";
    $headers .= "Reply-To: $mail\r\n";
    $headers .= "Return-Path: $mail\r\n";
    $headers .= 'MIME-Version: 1.0' . "\n";
    $headers .= 'Content-type: text/html; charset=utf-8'."\r\n";

    $to = 'support@pointstudiobg.com';
    $subject = 'Вътрешно съобщение от pointstudio';

    $status = mail($to, $subject, nl2br($message),$headers);


    $sql = 'INSERT INTO messages (podatel, mail, nfo, title, pitane) VALUES(\''.pg_escape_string($name).'\',\''.pg_escape_string($mail).'\',\''.pg_escape_string($nfo).'\',\''.pg_escape_string($title).'\',\''.pg_escape_string($question).'\');';
    $gCn->Execute($sql);

    echo '<h3>Благодаря, съобщението Ви беше изпратено успешно.</h3>';
//    echo '<br /><hr /><br />';
//    echo nl2br($message);
}

?>
